package com.cjh.mybatis08.type;

import lombok.NoArgsConstructor;

import java.lang.reflect.Type;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;

/**
 * @Descripton 类型处理器 注册机
 * @Author cjh
 * @Date 2023/6/12 14:45
 */
@NoArgsConstructor
public final class TypeHandlerRegistry {
    private final Map<JdbcType, TypeHandler<?>> JDBC_TYPE_HANDLER_MAP = new EnumMap<>(JdbcType.class);
    private final Map<Type,Map<JdbcType,TypeHandler<?>>> TYPE_HANDLER_MAP = new HashMap<>();

    private final Map<Class<?>,TypeHandler<?>> ALL_TYPE_HANDLERS_MAP = new HashMap<>();

    private void register(Type javaType,JdbcType jdbcType,TypeHandler<?> handler){
        if (null != javaType){
            Map<JdbcType,TypeHandler<?>> map = TYPE_HANDLER_MAP.
                    computeIfAbsent(javaType, k->new HashMap<>());
            map.put(jdbcType, handler);

        }
        ALL_TYPE_HANDLERS_MAP.put(handler.getClass(), handler);
    }
}
